package apps

import (
	casbin "github.com/casbin/gorm-adapter/v3"
	"go.uber.org/zap"
	"os"
	"server/apps/ads/ads_api"
	"server/apps/ads/ads_config"
	"server/apps/ads/ads_fld"
	"server/apps/ads/ads_topic"
	"server/apps/dm/dm_schema"
	"server/apps/dws/dws_api"
	"server/apps/dws/dws_fld"
	"server/apps/dws/dws_tb"
	"server/apps/dws/dws_topic"
	"server/apps/ods/ods_field"
	"server/apps/ods/ods_ftp"
	"server/apps/ods/ods_job"
	"server/apps/ods/ods_kafka"
	"server/apps/ods/ods_log"
	"server/apps/ods/ods_map"
	"server/apps/ods/ods_odb"
	"server/apps/ods/ods_supplier"
	"server/apps/ods/ods_table"
	"server/apps/uds/uds_fld"
	"server/apps/uds/uds_tb"
	"server/apps/xidw/xidw_mod"
	"server/global"
)

func MigrateTables() {
	db := global.SysDB
	err := db.AutoMigrate(

		xidw_mod.SysApi{},
		xidw_mod.SysUser{},
		xidw_mod.SysBaseMenu{},
		xidw_mod.JwtBlacklist{},
		xidw_mod.SysAuthority{},
		xidw_mod.SysDictionary{},
		xidw_mod.SysOperationRecord{},
		xidw_mod.SysDictionaryDetail{},
		xidw_mod.SysBaseMenuParameter{},
		xidw_mod.SysBaseMenuBtn{},
		xidw_mod.SysAuthorityBtn{},
		xidw_mod.FileUploadAndDownload{},
		casbin.CasbinRule{},

		ods_supplier.OdsSupplier{},
		ods_table.OdsDbTable{},
		ods_odb.OdsOdb{},
		ods_field.OdsDbField{},
		ods_job.OdsJob{},
		ods_log.OdsDbSyncLog{},
		ods_ftp.OdsFtp{},
		ods_kafka.OdsKafka{},

		ads_api.AdsApi{},
		ads_config.AdsConfig{},
		ads_topic.AdsTopic{},
		ads_fld.AdsFld{},

		dm_schema.DmSchema{},

		dws_topic.DwsTopic{},
		dws_api.DwsApi{},
		dws_fld.DwsFld{},
		dws_tb.DwsTb{},

		uds_fld.UdsFld{},
		uds_tb.UdsTb{},

		ods_map.DbFldMap{},
	)
	if err != nil {
		global.Logger.Error("register table failed", zap.Error(err))
		os.Exit(0)
	}
	global.Logger.Info("register table success")
}
